package com.example.chapter05;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "OrderServlet", value = "/OrderServlet")
public class OrderServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType( "text/html;charset=utf-8" );
        request.setCharacterEncoding( "utf-8" );
        String foodName[] =  request.getParameterValues("choice") ;
        if (foodName != null) {
            for (int k = 0; k <  foodName.length ; k++) {
                request.getSession() .setAttribute(foodName[k], foodName[k] );
            }
        }
        String url = "<A href='/chapter05_war_exploded/CartServlet'>  欢迎去购物车页面！</A>";
        response.getWriter().print("<P>点击超链接，链接到购物车页面,去查看购物车中的商品。<br />" + url);

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}